package com.woniu.smart.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniu.smart.dto.BuildingDTO;
import com.woniu.smart.entity.Building;
import com.woniu.smart.mapper.BuildingMapper;
import com.woniu.smart.service.BuildingService;
import com.woniu.smart.vo.BuildingVo;
import com.woniu.smart.vo.EChartsBuildingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 晨星
 * @date 2022/10/20/14:29
 */
@Service
public class BuildingServiceImpl implements BuildingService {

    @Autowired
    private BuildingMapper buildingMapper;

    /**
     * 查询所有楼栋信息
     *
     * @author 晨星
     * @date 2022/10/21 14:43
     * @return java.util.List<com.woniu.smart.entity.Building>
     **/
    @Override
    public List<BuildingVo> selectAll(BuildingDTO buildingDTO) {
        PageHelper.startPage(buildingDTO.getCurrentPage(), buildingDTO.getPageSize());
        return buildingMapper.selectAll(buildingDTO);
    }

    /**
     * 根据主键删除楼栋
     *
     * @author 晨星
     * @date 2022/10/20 21:32
     * @param id 主键id
     * @return int
     **/
    @Override
    public int deleteByPrimaryKey(Long id) {
        return buildingMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<Integer> buildingIds) {
        return buildingMapper.deleteBatch(buildingIds);
    }

    /**
     * 选择性新增楼栋信息
     *
     * @author 晨星
     * @date 2022/10/21 14:32
     * @param record 楼栋的实体类
     * @return int
     **/
    @Override
    public int insertSelective(Building record) {
        record.setBuildingLayers(record.getBuildingOver()+ record.getBuildingBelow());
        return buildingMapper.insertSelective(record);
    }

    /**
     * 根据id查询楼栋
     *
     * @author 晨星
     * @date 2022/10/21 14:30
     * @param id 主键id
     * @return com.woniu.smart.entity.Building
     **/
    @Override
    public Building selectByPrimaryKey(Long id) {
        return buildingMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据主键ID选择性修改楼栋信息
     *
     * @author 晨星
     * @date 2022/10/21 14:33
     * @param record 楼栋的实体类
     * @return int
     **/
    @Override
    public int updateByPrimaryKeySelective(Building record) {
        record.setBuildingLayers(record.getBuildingOver()+ record.getBuildingBelow());
        return buildingMapper.updateByPrimaryKeySelective(record);
    }
    /**
     * @Description 根据楼宇id查询包含的楼层数
     * @Parm a
     * @Retrn a
     * @Author WangMr
     * @Date Create by 2022/10/31 16:36
     */
    @Override
    public List<EChartsBuildingVO> selectGroupByBuilding() {
        return buildingMapper.selectGroupByBuilding();
    }
}
